thin.imports('/public/home/css/global.project.css');

thin.imports('/public/configure/conf.project.js');

thin.use(function() {

	// 路由
	checkLocation();

	$('a.weui-navbar__item').off('click').on('click', function(e) {
		var e = e || window.event;
		e.stopPropagation();
		var that = $(this),
			itor = that.attr('data-itor');
		that.addClass('weui-bar__item--on').siblings('a').removeClass('weui-bar__item--on');
		$(itor).addClass('weui-tab__bd-item--active').siblings('div').removeClass('weui-tab__bd-item--active');
		checkTab(itor);
		return false;
	});

	// 绑定项目未评估按钮
	$('#prolist-w').on('click', 'a', function() {
		window.location.href = '/mobile/project/review';
	});
	// 绑定项目已评估按钮
	$('#prolist-y').on('click', 'a', function() {
		window.location.href = '/mobile/chain/fund';
	});
});

var __getdata_prome = {},
	jude_project = false,
	jude_prow = false,
	jude_proy = false;

// 路由
function checkLocationCallback(hash) {
	if(!jude_project) {
		checkTab('#prolist-w');
		jude_project = true;
	}
}

function checkTab(itor) {
	if(/prolist-w/gi.test(itor)) {
		if(!jude_prow) {
			$.showLoading();
			__getdata_prome['model'] = 1;
			factory.request('_project_me', itor);
			jude_prow = true;
		}
	}

	if(/prolist-y/gi.test(itor)) {
		if(!jude_proy) {
			$.showLoading();
			__getdata_prome['model'] = 2;
			factory.request('_project_me', itor);
			jude_proy = true;
		}
	}
}

// 获取项目回调
function __complete_prome(res, unkn) {
	$.hideLoading();
	if(res.status == 200) {
		if(res.data.length > 0) {
			createProjectList(res.data, unkn);
			$(unkn).find('.nothing-box').hide();
		} else {
			$(unkn).find('#project-volist').html('');
			$(unkn).find('.nothing-box').show();
		}
	} else {
		$(unkn).find('#project-volist').html('');
		$(unkn).find('.nothing-box').show();
		$.toptip(res.error, 'error');
	}
}

// 创建项目列表
function createProjectList(data, itor) {
	var ele = '';
	for(var i in data) {
		var list = data[i];
		ele += '<a href="javascript:;" class="weui-media-box weui-media-box_appmsg weui-cell_access">';
		ele += '<div class="weui-media-box__hd">';
		ele += '<img class="weui-media-box__thumb pro-logo" src="' + list.logo + '" alt="">';
		ele += '</div>';
		ele += '<div class="weui-media-box__bd">';
		ele += '<h4 class="weui-media-box__title">' + list.title + '</h4>';
		ele += '<p class="weui-media-box__desc">' + list.words + '</p>';
		ele += '</div>';
		ele += '<span class="weui-cell__ft">查看</span>';
		ele += '</a>';
	}
	$(itor).find('#project-volist').html(ele);
}